package com.gin.kotlin.gf2gamecommunity.composable

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Person
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import coil3.compose.SubcomposeAsyncImage
import com.gin.kotlin.gf2gamecommunity.app.AvatarImageShow

@Composable
fun UserAvatar(url: String? = null, modifier: Modifier = Modifier) {
    AvatarImageShow { s, _ ->
        if (s.show(LocalContext.current)) {
            SubcomposeAsyncImage(model = url,
                contentDescription = "用户头像",
                loading = {
                    Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
                        CircularProgressIndicator()
                    }
                },
                modifier = modifier
            )
        } else {
            Icon(Icons.Filled.Person, "用户头像占位", modifier = modifier)
        }
    }
}